﻿using HWmanagementDB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace HWmanagementServer
{
    /*
     * ***********************************************************************************
     * THIS IS A TEMPORARY CLASS FOR TESTING THE DATABASE
     * ***********************************************************************************
     */

    public class AdminManager
    {
        public static void AddUser(UserModel user)
        {
            using (Repository repo = new Repository())
            {
                repo.UserRepository.Insert(UserModel.toDBTable(user));
            }
        }

        public static void AddSubject(SubjectModel subj)
        {
            using (Repository repo = new Repository())
            {
                repo.SubjectRepository.Insert(SubjectModel.toDBTable(subj));
            }
        }

        public static void AddCourse(string subj, string sem)
        {
            using (Repository repo = new Repository())
            {
                int max = 0;
                try
                {
                    max = repo.CourseRepository.Get().Max((c) => c.ID);
                }
                catch { }

                var su = repo.SubjectRepository.GetByID(subj);
                var cou = new COURSE() { ID = max + 1, SEMESTER = sem, SUBJECT = su };

                repo.CourseRepository.Insert(cou);

                repo.Save();
                
                su.COURSE.Add(cou);
                repo.SubjectRepository.Update(su);

            }
        }
    }
}
